home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / Z4CSBLD.C < prev    next >
C/C++ Source or Header  |  1995-08-17  |  5KB  |  189 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    z4csbld.c
  5. //   Title:    9-Digit ZIP Code Directory -- on CD-ROM
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //    This module contains the program entry point for
  24. //
  25. //    The code in this module may be written in C++ or C.
  26. //
  27. //    This module is portable to:
  28. //        DOS 3.X+
  29. //        MS Windows 3.X+
  30. //        OS/2 2.X+
  31. //        OS/2 2.0 PM
  32. //
  33. //    The following compilers are supported:
  34. //        MSC 6.0A
  35. //        MSC/C++ 7.0
  36. //        Borland C++ 3.1 for DOS
  37. //        Borland C++ 1.0 for OS/2 2.X
  38. //
  39. //----------------------------------------------------------------------------
  40. #include <z4.h>
  41.  
  42.  
  43. //----------------------------------------------------------------------------
  44. //    Stack size
  45. //----------------------------------------------------------------------------
  46. #if COMPILER_BORLAND && (OS_DOS || OS_WINDOWS)
  47. unsigned _stklen = 0x4000;
  48. #endif
  49.  
  50.  
  51. //----------------------------------------------------------------------------
  52. //    Globals
  53. //----------------------------------------------------------------------------
  54.  
  55. //
  56. // A useless string which is simply embedded in the executable.
  57. //
  58. PSZ __pszCredits__ = "Written by John M Weeder, 1993";
  59.  
  60.  
  61. //
  62. //    This should contain a program description which will be displayed as
  63. //    part of the program's help text.
  64. //
  65. static PCSZ pcszDescription =
  66.     "This program builds the city/state primary data files";
  67.  
  68. //
  69. //    Program command line options
  70. //
  71. static DATACFG dcfg;
  72. static BOOL fStrip = FALSE;
  73. static BOOL fSort = FALSE;
  74. static BOOL fCompress = FALSE;
  75. static BOOL fIndex = FALSE;
  76. static BOOL fRecNo = FALSE;
  77. static BOOL fCheck = FALSE;
  78. static CHAR szConfig[MAX_PATH] = "z4cs";
  79. static BS_CMDOPT acmdopt[] =
  80.     {
  81.     { "CHECK",        (PVOID)&fCheck,        CMDOPT_TRUE,             "Validate CRC codes."},
  82.     { "COMPRESS",    (PVOID)&fCompress,    CMDOPT_TRUE,             "Compress data file."},
  83.     { "INDEX",        (PVOID)&fIndex,        CMDOPT_TRUE,             "Index data file."},
  84.     { "RECNO",        (PVOID)&fRecNo,        CMDOPT_TRUE,             "Process record count file."},
  85.     { "STRIP",       (PVOID)&fStrip,         CMDOPT_TRUE,             "Strip fixed length data file."},
  86.     { "SORT",       (PVOID)&fSort,         CMDOPT_TRUE,             "Sort stripped data file."},
  87.     { "config",     (PVOID)szConfig,        CMDOPT_FILESPEC(80), "Configuration file name."},
  88.     BS_CMDOPT_NULL,
  89.     };
  90.  
  91.  
  92. //----------------------------------------------------------------------------
  93. //   Description:    
  94. //    Parameters:
  95. //       Returns:    
  96. //----------------------------------------------------------------------------
  97. VOID FN_E Z4Strip(PDATACFG pcfg, PRECID precid, PSZ _FAR_ *apsz, PBYTE pb)
  98. {
  99. static SIZET cCity;
  100. static SIZET cCityAbbrev;
  101. static SIZET cLLName;
  102.  
  103.     NOTUSED(precid);
  104.     NOTUSED(pb);
  105.     if (apsz == NULL)
  106.         {
  107.         cCity       = DataField(pcfg, "city_name");
  108.         cCityAbbrev = DataField(pcfg, "city_abbrev");
  109.         cLLName    = DataField(pcfg, "last_line_name");
  110.         return ;
  111.         }
  112.     Z4Clean(apsz[cCity]);
  113.     Z4Clean(apsz[cCityAbbrev]);
  114.     Z4Clean(apsz[cLLName]);
  115.     return ;
  116. }
  117.  
  118.  
  119. //----------------------------------------------------------------------------
  120. //   Description:    main() - Program entry point
  121. //    Parameters:    Standard C parameters
  122. //       Returns:    DOS return code.
  123. //----------------------------------------------------------------------------
  124. int main(int argc, char **argv)
  125. {
  126. static BS_CFG cfg = CFG_DFT;
  127.     int retval = 99;
  128.  
  129.     //
  130.     //    Initialize base library
  131.     //
  132.     BaseLibraryInitialize(argc, argv, &cfg);
  133.     BaseTitle("$Revision:  93.1  $", __DATE__, __TIME__, "ZIP+4 City/State File Build");
  134.     if (!BaseTitleHelp(acmdopt, pcszDescription,0))
  135.         return 99;
  136.  
  137.     DioSetDataPath(getenv("DATA"));
  138.     if (!DataConfigRead(szConfig, &dcfg))
  139.         {
  140.         Output("Failed reading configuration file.\n");
  141.         goto ERROR_EXIT;
  142.         }
  143.     if (fStrip)
  144.         if (!DataStrip(&dcfg, Z4Strip))
  145.            {
  146.            Output("Failed stripping fixed length records.\n");
  147.            goto ERROR_EXIT;
  148.            }
  149.     if (fSort)
  150.        if (!DataSort(&dcfg))
  151.            {
  152.            Output("Failed sorting delimited data file.\n");
  153.            goto ERROR_EXIT;
  154.            }
  155.     if (fCompress)
  156.         {
  157.        if (!DataCompress(&dcfg, Z4CSCompress, DAC_XREF|DAC_RECNO))
  158.            {
  159.            Output("Failed compressing delimited data file.\n");
  160.            goto ERROR_EXIT;
  161.            }
  162.         }
  163.     if (fRecNo)
  164.         if (!DataRecNo(&dcfg))
  165.            {
  166.            Output("Failed generating record number index.\n");
  167.            return 99;
  168.            }
  169.     if (fIndex)
  170.         if (!DataIndex(&dcfg, Z4CSIndex))
  171.            {
  172.            Output("Failed indexing CS data file.\n");
  173.            return 99;
  174.            }
  175.     if (fCheck)
  176.         if (!DioCheck(dcfg.szData))
  177.            {
  178.            Output("Failed verifying data file.\n");
  179.            return 99;
  180.            }
  181.     retval = 0;
  182. ERROR_EXIT:
  183.     DioCloseAll();
  184.     return retval;
  185. }
  186. //----------------------------------------------------------------------------
  187. //------------------------------- End of File --------------------------------
  188. //----------------------------------------------------------------------------
  189.